package com.ys.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.bo.util.DateUtil;

public class OrderUtil {
	
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
	
	/*
	 * 
	 */
	public static String getOrderNoOfWithdraw(Integer type){
		String str = "TX" + sdf.format(new Date()) + createRandomNumCode(2);
		
		return str;
	}
	
	/*
	 * 
	 */
	public static String getOrderNoOfSpiderTask(){
		String str = "RW" + sdf.format(new Date()) + createRandomNumCode(2);
		
		return str;
	}
	
	/*
	 * 获取best seller的任务号
	 */
	public static String getOrderNoOfSpTask(String link, String codeLast){
		String code1 = link.startsWith("https://www.amazon.com") ? "US" : "UK";
		String code2 = DateUtil.getYYYY_MM_DD(new Date()).replace("-", "");
		String code3 = "0001";
		if (codeLast != null && codeLast.length() > 0 && code2.equals(codeLast.substring(2, 10))) {
			Integer num = Integer.parseInt(codeLast.substring(codeLast.length() - 4)) + 1;
			code3 = num > 999 ? "" + num
					: num > 99 ? "0" + num
					: num > 9 ? "00" + num
					: ("000" + num);
		}
		
		return code1 + code2 + code3;
	}
	
	/*
	 * 获取best seller的任务详情号
	 */
	public static String getOrderNoOfSpTaskDetail(String codeTask, String codeLast){
		
		if (codeLast == null || codeLast.length() == 0) {
			return codeTask + "000001";
		}
		Integer num = Integer.parseInt(codeLast.substring(codeLast.length() - 6)) + 1;
		
		String codeNum = num > 99999 ? "" + num
				: num > 9999 ? "0" + num
				: num > 999 ? "00" + num
				: num > 99 ? "000" + num
				: num > 9 ? "0000" + num
				: ("00000" + num);
		
		return codeTask + codeNum;
	}
	
	/*
	 * 
	 */
	public static String getDevelopDetailCode(Date date, Integer numIn){
		String yyMMdd = DateUtil.getYYYY_MM_DD(date).replace("-", "").substring(2);
		
		String postStr = "";
		if (numIn < 10) {
			postStr = "00000" + numIn;
		} else if (numIn < 100) {
			postStr = "0000" + numIn;
		} else if (numIn < 1000) {
			postStr = "000" + numIn;
		} else if (numIn < 10000) {
			postStr = "00" + numIn;
		} else if (numIn < 100000) {
			postStr = "0" + numIn;
		} else {
			postStr = "" + numIn;
		}
		String str = "PD" + yyMMdd + postStr;
		
		return str;
	}
	
	/*
	 * 获取部门编码
	 */
	public static String getDeptCode(Integer num){
		String postStr = "";
		if (num < 10) {
			postStr = "00" + num;
		} else if (num < 100) {
			postStr = "0" + num;
		} else {
			postStr = "" + num;
		}
		String str = "BM" + postStr;
		
		return str;
	}
	
	/*
	 * 获取岗位编码
	 */
	public static String getStationCode(Integer num){
		String postStr = "";
		if (num < 10) {
			postStr = "00" + num;
		} else if (num < 100) {
			postStr = "0" + num;
		} else {
			postStr = "" + num;
		}
		String str = "GW" + postStr;
		
		return str;
	}
	
	/*
	 * 获取员工编码
	 */
	public static String getUserCode(Integer num){
		String postStr = "";
		if (num < 10) {
			postStr = "0000" + num;
		} else if (num < 100) {
			postStr = "000" + num;
		} else if (num < 1000) {
			postStr = "00" + num;
		} else if (num < 10000) {
			postStr = "0" + num;
		} else {
			postStr = "" + num;
		}
		
		return postStr;
	}
	
	/*
	 * 生成随机验证码
	 */
	private static String createRandomNumCode(int length) {
		String code = "";
		for (int i = 0; i < length; i++) {
			int c = (int) (Math.random() * 10);
			code += c;
		}
		return code;
	}
	
	/**
	 * 生成0字符串
	 * @param length 长度
	 * @return
	 */
	public static String createZero(int length) {
		String code = "";
		for (int i = 0; i < length; i++) {
			code += "0";
		}
		return code;
	}
}
